#include <cstdio>
#include <cstring>
#include <queue>

const int N = 100005;
int n, k, s, t, d2;
int e_cnt = 1, heads[N], dis[N], fa[N], maxlen[N];
bool vis[N];

struct Edge {
  int v, nxt, w;
} e[N << 1];

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt, e[e_cnt].w = 1;
}

inline int bfs() {
  int res = s;
  memset(vis, false, sizeof(vis));
  memset(dis, 0, sizeof(dis));
  std::queue<int> q;
  q.push(s);
  dis[s] = 0, fa[s] = s, vis[s] = true;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = heads[u], v; i; i = e[i].nxt) {
      if (!vis[v = e[i].v]) {
        dis[v] = dis[u] + e[i].w;
        fa[v] = u;
        if (dis[v] > dis[res]) res = v;
        q.push(v);
        vis[v] = true;
      }
    }
  }
  return res;
}

void dfs(int u, int fa) {
  maxlen[u] = 0;
  for (int i = heads[u], v; i; i = e[i].nxt) {
    if ((v = e[i].v) != fa) {
      dfs(v, u);
      d2 = std::max(d2, maxlen[v] + e[i].w + maxlen[u]);
      maxlen[u] = std::max(maxlen[u], maxlen[v] + e[i].w);
    }
  }
}

void change(int x) {
  if (fa[x] == x) return;
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if ((v = e[i].v) == fa[x]) {
      change(v);
      e[i].w = e[i ^ 1].w = -1;
    }
  }
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("CppTest.in", "r", stdin);
  freopen("CppTest.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &k);
  for (int i = 1, a, b; i < n; ++i) {
    scanf("%d%d", &a, &b);
    add(a, b), add(b, a);
  }
  s = 1;
  s = bfs();
  t = bfs();
  if (k == 1) {
    printf("%d", ((n - 1) << 1) - dis[t] + 1);
    return 0;
  }
  change(t);
  dfs(1, 1);
  printf("%d", ((n - 1) << 1) - dis[t] - d2 + 2);
  return 0;
}